using System;
using System.Collections.Generic;
using Caliburn.Micro;
using Ninject;
using Updater.Wpf.SimpleApp.ViewModels;

namespace Updater.Wpf.SimpleApp
{
    /// <summary>
    /// Caluburn.Micro application bootstrapper using NInject. There is no updater-specific logic
    /// here.
    /// </summary>
    public class AppBootstrapper : Bootstrapper<ShellViewModel>
    {
        private IKernel kernel;

        protected override void Configure()
        {
            this.kernel = new StandardKernel();

            this.kernel.Bind<IWindowManager>().To<WindowManager>().InSingletonScope();
            this.kernel.Bind<IEventAggregator>().To<EventAggregator>().InSingletonScope();
            this.kernel.Bind<ShellViewModel>().ToSelf().InSingletonScope();
        }

        protected override object GetInstance(Type serviceType, string key)
        {
            if (serviceType != null)
            {
                return this.kernel.Get(serviceType);
            }

            throw new ArgumentNullException("serviceType");
        }

        protected override IEnumerable<object> GetAllInstances(Type serviceType)
        {
            return this.kernel.GetAll(serviceType);
        }

        protected override void BuildUp(object instance)
        {
            this.kernel.Inject(instance);
        }
    }
}
